package com.mp.dao;

import com.mp.db.jpa.util.JPAUtil;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.NonUniqueResultException;
import javax.persistence.Query;


public abstract class GenericoDAO 
{
    protected EntityManager em = JPAUtil.getEntity();
    
    public Object getSingleResultOrNull(Query query)
    {
        List results = query.getResultList();
        
        if (results.isEmpty()) 
        {
            return null;
        }
        else
        {
            if (results.size() > 0) 
            {
              return results.get(0);
            }
        } 
         
        throw new NonUniqueResultException();
    }
     
}
